<?php 
	function displayUserProperty($user, $property) {
		if(isset($user[$property])) {
			echo $user[$property];
		}
	}
	
	function isHasGroupId($groupIds, $checkValue) {
		if(isset($groupIds)) {
			foreach ($groupIds as $groupId) {
				if($groupId == $checkValue) {
					return true;
				}
			}
		}
		return false;
	}
?>
<script type="text/javascript" language="javascript">
	function submitform(pressbutton) {
		var form = document.adminForm;
		form.pressbutton.value=pressbutton;
		form.submit();
	}
	
	function submitbutton(pressbutton) {
		var form = document.adminForm;
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}

		// do field validation
		if ($.trim(form.full_name.value) == "") {
			alert( "You must provide a name." );
		} else if (form.username.value == "") {
			alert( "You must provide a User Login Name." );
		} else if (form.username.value.length < 2) {
			alert( "Your username is too short." );
		} else if ($.trim(form.email.value) == "") {
			alert( "You must provide an e-mail address." );
		} else if (form.gid.value == "") {
			alert( "You must assign the User to a Group." );
		} else if ((($.trim(form.password.value) != "") || ($.trim(form.password2.value) != "")) && (form.password.value != form.password2.value)){
			alert( "Passwords Do Not Match." );
		} else if (form.gid.value == "29") {
			alert( "Please select another Group. Public Front-end is not a selectable option." );
		} else if (form.gid.value == "30") {
			alert( "Please select another Group. Public Back-end is not a selectable option." );
		} else {
			submitform( pressbutton );
		}
	}

</script>

<div class="border">
	<div class="padding">
		<div id="toolbar-box">
			<div class="t">
				<div class="t">
					<div class="t"></div>
				</div>
			</div>
			<div class="m">
				<div id="toolbar" class="toolbar">
					<table class="toolbar">
						<tbody>
							<tr>
								<td id="toolbar-save" class="button"><a class="toolbar"
									onclick="javascript: submitbutton('save')" href="#"> <span
										title="Save" class="icon-32-save"> </span> Save </a></td>


								<td id="toolbar-cancel" class="button"><a class="toolbar"
									onclick="javascript: submitbutton('cancel')" href="#"> <span
										title="Cancel" class="icon-32-cancel"> </span> Cancel </a></td>

								<td id="toolbar-help" class="button"><a class="toolbar"
									onclick="popupWindow('http://help.joomla.org/index2.php?option=com_content&amp;task=findkey&amp;tmpl=component;1&amp;keyref=screen.users.edit.15', 'Help', 640, 480, 1)"
									href="#"> <span title="Help" class="icon-32-help"> </span> Help
								</a></td>

							</tr>
						</tbody>
					</table>
				</div>
				<div class="header icon-48-user">
					User: <small><small>[ New ]</small>
					</small>
				</div>

				<div class="clr"></div>
			</div>
			<div class="b">
				<div class="b">
					<div class="b"></div>
				</div>
			</div>
		</div>
		<div class="clr"></div>

		<div id="element-box">
			<div class="t">
				<div class="t">
					<div class="t"></div>
				</div>
			</div>
			<div class="m">

				<form autocomplete="off" name="adminForm" method="post"
					action="/admin?c=user&a=editSubmit">
					<input type="hidden" name="id" id="id" value="<?php echo $this->updatedUser["id"]?>">
					<input type="hidden" name="pressbutton" value="cancel">
					<div class="col" style="width:100%;text-align: center;">
						<fieldset class="adminform">
							<legend>User Details</legend>
							<table cellspacing="1" class="admintable">
								<tbody>
									<tr>
										<td class="key"><label for="username"> Username </label></td>
										<td><input type="text" autocomplete="off" value="<?php displayUserProperty($this->updatedUser, 'username');?>" size="40"
											class="inputbox" id="username" name="username" disabled="disabled"></td>
									</tr>
									<tr>
										<td class="key"><label for="username"> Fullname </label></td>
										<td><input type="text" autocomplete="off" value="<?php displayUserProperty($this->updatedUser, 'full_name');?>" size="40"
											class="inputbox" id="full_name" name="full_name"></td>
									</tr>
									<tr>
										<td class="key"><label for="email"> E-mail </label></td>
										<td><input type="text" value="<?php echo displayUserProperty($this->updatedUser, 'email');?>" size="40" id="email"
											name="email" class="inputbox" disabled="disabled"></td>
									</tr>
									<tr>
										<td class="key"><label for="password"> New Password </label></td>
										<td><input type="password" value="<?php displayUserProperty($this->updatedUser, 'password');?>" size="40" id="password"
											name="password" class="inputbox"></td>
									</tr>
									<tr>
										<td class="key"><label for="password2"> Verify Password </label>
										</td>
										<td><input type="password" value="<?php displayUserProperty($this->updatedUser, 'password');?>" size="40" id="password2"
											name="password2" class="inputbox"></td>
									</tr>
									<tr>
										<td valign="top" class="key"><label for="gid"> Group </label>
										</td>
										<td>
											<select size="3" id="gid" name="gid[]" style="width:175px;" multiple="multiple">
												<!-- FIXME:Hardcode here. Need to lookup values from ipoo_user table -->
												<option value="1" <?php if(isHasGroupId($this->groupIds, 1)) echo "selected";?>>Admin</option>
												<option value="2" <?php if(isHasGroupId($this->groupIds, 2)) echo "selected";?>>User</option>
												<option value="3" <?php if(isHasGroupId($this->groupIds, 3)) echo "selected";?>>Guest</option>
											</select>
										</td>
									</tr>
								</tbody>
							</table>
						</fieldset>
					</div>
					<div class="clr"></div>

				</form>

				<div class="clr"></div>
			</div>
			<div class="b">
				<div class="b">
					<div class="b"></div>
				</div>
			</div>
		</div>
		<noscript>Warning! JavaScript must be enabled for proper operation of
			the Administrator back-end.</noscript>
		<div class="clr"></div>
	</div>
	<div class="clr"></div>
</div>
